package elicecn;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import SevenZip.Compression.LZMA.Encoder;

/**
 * @author 屹砾
 * @email gongliang@outlook.com
 * @time 2014-3-27 下午3:56:46
 */
public class Zip7 {
	public static void encode(File srcFile, File destFile) throws Exception {
		BufferedInputStream in = new BufferedInputStream(new FileInputStream(
				srcFile));
		BufferedOutputStream out = new BufferedOutputStream(
				new FileOutputStream(destFile));
		Encoder encoder = new Encoder();
		encoder.SetEndMarkerMode(false);
		encoder.WriteCoderProperties(out);
		long fileSize = srcFile.length();
		for (int i = 0; i < 8; i++) {
			out.write((int) (fileSize >>> (8 * i)) & 0xFF);
		}
		encoder.Code(in, out, -1, -1, null);
		out.flush();
		out.close();
		in.close();
	}

	public static DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");

	// 必须原文件名加后缀.7z，压缩包内原文件名才正常
	public static void main(String[] args) throws Exception {
		String file = "/AutoFetchDataFile/2014/bonc-0-NA_114_12580-20140327-145552.csv";
		File srcFile = new File(file);
		File destFile = new File(file + ".7z");
		encode(srcFile, destFile);
	}
}
